﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XTYAPI.PLC
{
    /// <summary>
    /// 时间累加器
    /// </summary>
   public class TONR:TON
    {
        
        R_TRIG r_TRIG = new R_TRIG();
        F_TRIG f_TRIG = new F_TRIG();
        F_TRIG f_TRIG1 = new F_TRIG();
        bool q;
        uint et;//暂存当前
        uint et1;
        public TONR()
        {
            //base.TONMode = TONMode.Alaways;
        }
        public new bool IN
        {
            set
            {
                f_TRIG.CLK= r_TRIG.CLK = value;
                if (f_TRIG.Q)
                {
                    et = ET;
                    base.IN = false;                 
                }
                if (r_TRIG.Q)
                {
                    if (Q) return;
                    base.PT = PT - et;
                    base.IN = true;
                }
                base.IN = value;
            }
        }
        public bool R { set { if (value) { base.IN = false; base.PT = PT; et = 0; } else { base.IN = true; } } }
        public new uint PT { get; set; }
        public new uint ET { get { et1 = base.ET + et; return (et1 >( base.PT + et))? base.PT: et1; } }
        public new bool Q { get { q= base.Q ; return ET >= PT; } }
    }
}
